﻿Imports Microsoft.Win32

Public Class frmSettings
    Private Sub chkRun_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRun.CheckedChanged
        'SETS THE REGISTRY VALUE TO HAVE PROGRAM LOAD ON STARTUP
        Dim regShell As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)

        If chkRun.Checked = True Then
            regShell.SetValue("SysPad", Application.ExecutablePath)
        ElseIf chkRun.Checked = False Then
            regShell.DeleteValue("SysPad", True)
        End If

        regShell.Close()
    End Sub

    Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'CODE TO DETERMINE IF CHECKBOX FOR SYSTEM STARTUP RUN SHOULD BE CHECKED
        Dim regShell As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)

        If regShell.GetValue("SysPad") = Application.ExecutablePath Then
            chkRun.Checked = True
        End If

        If My.Settings.traypad_start = 1 Then
            chkTrayLaunch.Checked = True
        End If

        If My.Settings.uncEnabled = 1 Then
            chkUNC.Checked = True
        End If

        regShell.Close()

        NPPathBrowseDiag.RootFolder = Environment.SpecialFolder.MyComputer

        txtNPPath.Text = My.Settings.npPath
    End Sub

    Private Sub txtInterval_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        My.Settings.Save()
    End Sub

    Private Sub chkTrayLaunch_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTrayLaunch.CheckedChanged
        If chkTrayLaunch.Checked = True Then
            My.Settings.traypad_start = 1
        ElseIf chkTrayLaunch.Checked = False Then
            My.Settings.traypad_start = 0
        End If
    End Sub

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        My.Settings.Save()
        Me.Dispose()
    End Sub

    Private Sub chkUNC_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUNC.CheckedChanged
        If chkUNC.Checked = True Then
            My.Settings.uncEnabled = 1
        ElseIf chkUNC.Checked = False Then
            My.Settings.uncEnabled = 0
        End If
    End Sub

    Private Sub bgColorDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bgColorDialog.Click
        'ALLOWS USER TO CHANGE THE "PAD's" BACKGROUND COLOR FOR ALL TEXTBOX's
        'UPDATES IMMEDIATELY
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            lblFont.BackColor = ColorDialog1.Color
            TrayPad.tabPage1.BackColor = ColorDialog1.Color
            TrayPad.tabPage2.BackColor = ColorDialog1.Color
            TrayPad.tabPage3.BackColor = ColorDialog1.Color
            TrayPad.tabPage4.BackColor = ColorDialog1.Color
            TrayPad.tabPage5.BackColor = ColorDialog1.Color
            FolderPad.folderList.BackColor = ColorDialog1.Color
            My.Settings.Save()
        End If
    End Sub

    Private Sub fontColorDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fontColorDialog.Click
        'ALLOWS USER TO CHANGE THE "PAD's" FONT COLOR FOR ALL TEXTBOX's
        'UPDATES IMMEDIATELY
        If ColorDialog2.ShowDialog() = Windows.Forms.DialogResult.OK Then
            lblFont.ForeColor = ColorDialog2.Color
            TrayPad.tabPage1.ForeColor = ColorDialog2.Color
            TrayPad.tabPage2.ForeColor = ColorDialog2.Color
            TrayPad.tabPage3.ForeColor = ColorDialog2.Color
            TrayPad.tabPage4.ForeColor = ColorDialog2.Color
            TrayPad.tabPage5.ForeColor = ColorDialog2.Color
            FolderPad.folderList.ForeColor = ColorDialog2.Color
            My.Settings.Save()
        End If
    End Sub

    Private Sub fontDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fontDialog.Click
        'ALLOWS USER TO CHANGE THE "PAD's" FONT TYPE FOR ALL TEXTBOX's
        'UPDATES IMMEDIATELY
        If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            lblFont.Font = FontDialog1.Font
            TrayPad.tabPage1.Font = FontDialog1.Font
            TrayPad.tabPage2.Font = FontDialog1.Font
            TrayPad.tabPage3.Font = FontDialog1.Font
            TrayPad.tabPage4.Font = FontDialog1.Font
            TrayPad.tabPage5.Font = FontDialog1.Font
            FolderPad.folderList.Font = FontDialog1.Font
            My.Settings.Save()
        End If
    End Sub

    Private Sub btnNPBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNPBrowse.Click
        If NPPathBrowseDiag.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If System.IO.File.Exists(NPPathBrowseDiag.SelectedPath & "\Notepad++.exe") = True Then
                My.Settings.npPath = NPPathBrowseDiag.SelectedPath
                txtNPPath.Text = NPPathBrowseDiag.SelectedPath
                My.Settings.Save()
                TrayPad.mnuExportToNP.Enabled = True
                TrayPad.mnuNotePad.Enabled = True
            Else
                MessageBox.Show("Notepad++.exe is not in this folder." & vbNewLine & "Executable path not set.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
            End If
        End If
    End Sub
End Class